﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using HidesaburoDotNET.Core;
using HidesaburoDotNET.Core.Detecctors;

namespace HidesaburouDotNetTest.Test.YakuCheck
{
    public partial class YakuDetectorsTest
    {
        [Test]
        public void TestDaiSangen()
        {
            YakuDetector detector = new DaisangenDetector();
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 13;
            //面前＋ツモ上がり
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Hatsu)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Chun)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),//カンを含む
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Chun)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            //失敗のテスト
            expectedFan = 0;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai,Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu , 0)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Chun)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            expectedFan = 0;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai,Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu , 0)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Ton)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);
        }
        [Test]
        public void TestShoSangen()
        {
            YakuDetector detector = null;
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 13;
            //面前＋ツモ上がり
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Hatsu)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Chun)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),//カンを含む
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Chun)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            //失敗のテスト
            expectedFan = 0;

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),//カンを含む
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Ton)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

        }
        [Test]
        public void TestToitoi()
        {
            YakuDetector detector = new ToitoiDetector();
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 2;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Pinzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Pinzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Ankan,new Hai( HaiType.Souzu , 7))
                });
            agari.SelectAgariHai(0, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            //正常でないときの判定
            expectedFan = 0;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Pinzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Jihai , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 7))
                });
            agari.SelectAgariHai(1, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);


        }

        [Test]
        public void TestTsuiso()
        {
            YakuDetector detector = new TsuisoDetector();
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 13;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            //正常でないときの判定
            expectedFan = 0;
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Manzu , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 3))
                });
            agari.SelectAgariHai(1, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu,2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , 3))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

        }
        /// <summary>
        /// チューレンのテスト
        /// </summary>
        [Test]
        public void TestChuren()
        {
            YakuDetector detector = new ChurenDetector();
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 13;
            //面前＋ツモ上がり
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu , 1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Manzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Manzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Manzu , 7)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Manzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);


            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 7)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);


            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 3)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            //失敗のテスト
            expectedFan = 0;

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_M,new Hai( HaiType.Souzu , 3)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 6)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);


            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 5)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 7)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Souzu , 2)),
                MockAgariTehai.CreateMentsu(MentsuType.Ankan,new Hai( HaiType.Souzu,1)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 4)),
                MockAgariTehai.CreateMentsu(MentsuType.Syuntsu_A,new Hai( HaiType.Souzu , 7)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Souzu , 9))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = false;
            AssertCorrectlyChecked(expectedFan, detector, agari);

        }
        /// <summary>
        /// 大四喜のテスト
        /// </summary>
        [Test]
        public void TestDaisushi()
        {
            YakuDetector detector = new DaisusiDetector();
            MockAgariTehai agari = null;
            int expectedFan = 0;

            //正常時の判定
            expectedFan = 13;
            //面前＋ツモ上がり
            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu , 5)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai,Hai.Ton)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Nan)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Sha)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Pe))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);


            //失敗のテスト
            expectedFan = 0;

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Manzu , 5)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai,Hai.Ton)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Haku)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Sha)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Pe))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);

            agari = new MockAgariTehai(new List<Mentsu>(){
                MockAgariTehai.CreateMentsu(MentsuType.Toitsu,new Hai( HaiType.Jihai , Hai.Nan)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai,Hai.Ton)),
                MockAgariTehai.CreateMentsu(MentsuType.Minkan,new Hai( HaiType.Jihai , Hai.Hatsu)),
                MockAgariTehai.CreateMentsu(MentsuType.Minko,new Hai( HaiType.Jihai , Hai.Sha)),
                MockAgariTehai.CreateMentsu(MentsuType.Anko,new Hai( HaiType.Jihai , Hai.Pe))
                });
            agari.SelectAgariHai(2, 0);
            agari.Tsumo = true;
            AssertCorrectlyChecked(expectedFan, detector, agari);
        }

    }
}
